package com.gzsxy.esjy.service.statistical.listener;

import com.gzsxy.esjy.bus.event.InnerProtocolMessageEvent;
import com.gzsxy.esjy.bus.message.InnerProtocol;
import com.gzsxy.esjy.service.base.DictionaryConstants;
import com.gzsxy.esjy.service.base.dto.response.OrderCountRsp;
import com.gzsxy.esjy.service.statistical.service.StatisicalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 订单服务消息监听
 * @date 2022/3/3 9:03
 */
@Component
@Slf4j
public class AuthEventListener {


    @Autowired
    private StatisicalService statisicalService;

    @EventListener(InnerProtocolMessageEvent.class)
    public void event(InnerProtocolMessageEvent event){
        InnerProtocol message = event.getMessage();
        String cmd = message.getCmd();
        OrderCountRsp orderCountRsp = (OrderCountRsp) message.getBody();
        log.info("监听到商家id为【{}】的订单总价为【{}】",orderCountRsp.getUserId(),orderCountRsp.getOrderNum());
        //如果新增订单数
        if (DictionaryConstants.ORDER_NUM.equals(cmd)){
            statisicalService.updateStatisicals(orderCountRsp.getUserId(),orderCountRsp.getSalesNum());
            //如果新增订单总额
        }
    }
}
